<?xml version="1.0" encoding="UTF-8"?>
<!-- updated on 6th June
        This file use a fake presentation file called testing.xml under TestingDiagram folder for testing-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:MASC_Profile="http:///schemas/MASC_Profile/_OnYS4BTgEd6yO-ZURVEtWw/6"
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
    xmlns:uml="http://www.eclipse.org/uml2/2.1.0/UML"
    xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
    xmlns:masc-gp="http://www.sce.unsw.edu.au/~vtosic/ws-policy4masc/masc-gp"
    xmlns:masc-se="http://www.sce.unsw.edu.au/~vtosic/ws-policy4masc/masc-se"
    xmlns:masc-ex="http://www.sce.unsw.edu.au/~vtosic/ws-policy4masc/masc-ex"
    xmlns:masc-om="http://www.sce.unsw.edu.au/~vtosic/ws-policy4masc/masc-om"
    xmlns:masc-sc="http://www.sce.unsw.edu.au/~vtosic/ws-policy4masc/masc-sc"
    xmlns:masc-ap="http://www.sce.unsw.edu.au/~vtosic/ws-policy4masc/masc-ap"
    xmlns:masc-mp="http://www.sce.unsw.edu.au/~vtosic/ws-policy4masc/masc-mp"
    xmlns:masc-up="http://www.sce.unsw.edu.au/~vtosic/ws-policy4masc/masc-up"
    xmlns:masc-config="http://www.nicta.com.au/projects/armature/masc-config"
    xmlns:wsa="http://www.sce.unsw.edu.au/~vtosic/ws-policy4masc/wsa"
    xmlns:editmodel="editmodel.xmi"
    xmlns:options="options.xmi"
    xmlns:QoSOntology="http://www.myontologyrepository.com/qosontology.owl"
    xmlns:tns="${currentFileURL}" xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs" version="2.0">

    <xsl:param name="xmiFile" select="document('../TestingDiagram/UML.xml')"/>
    <xsl:param name="presentationLocation" select="$xmiFile/uml:Model/packagedElement/eAnnotations/@source"/>
    <!-- the two params above only needed while it needs read presentation xml url from XMI -->
    <!-- we assume that presentation xml file name and location already knows -->
    <xsl:param name="presentationFile" select="document('../TestingDiagram/testing.xml')"/>
    <xsl:param name="eventData" select="document('../Fake_MASC_EventData.xml')"/>
    
    <xsl:param name="newline" select="'&#10;'"/>

    <xsl:template match="/">
        <xsl:apply-templates select="*"/>
    </xsl:template>
    
    <!-- copy all content which @note != 'NOTE'
            for element that @note = 'NOTE', update it -->
    <xsl:template  match="*">
        <xsl:copy>
            <xsl:copy-of  select="@*[not(starts-with(., 'Measurement Runtime Data'))]"/>
            <xsl:apply-templates  select="@note[starts-with(., 'Measurement Runtime Data')]"/>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>
    
    <!-- update element with @note = 'NOTE' -->
    <xsl:template  match="@note[starts-with(., 'Measurement Runtime Data')]">
        <xsl:attribute  name="note">
            <xsl:value-of select="."/>
            <xsl:value-of select="$newline"/>
            <xsl:call-template name="noteUpdate"/>
        </xsl:attribute>
    </xsl:template> 
    
    <!-- template for content updated in note -->
    <xsl:template name="noteUpdate">
        <xsl:for-each select="$eventData/MASCEventData/EventGroup">
            <xsl:value-of select="position()"/>
            <xsl:text>. </xsl:text>
            <xsl:value-of select="./Event[1]/@EventName"/>    
            <xsl:value-of select="./Event[1]/EventParameters/text()"/>
            <xsl:text> </xsl:text>
            <xsl:value-of select="./Event[1]/@TimeStamp"/>                    
            <xsl:value-of select="$newline"/>
        </xsl:for-each>  
    </xsl:template>

</xsl:stylesheet>
